package com.broheim.websocket.core.endpoint.context;

import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

public class ChannelContextManager {

    public static Set<ChannelContext> channelContextSet = new CopyOnWriteArraySet<>();

    public static void add(ChannelContext channelContext) {
        channelContextSet.add(channelContext);
    }

    public static void remove(ChannelContext channelContext) {
        channelContextSet.remove(channelContext);
    }

    public static void broadcast(String message) {
        for (ChannelContext channelContext : channelContextSet) {
            try {
                channelContext.sendText(message);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
